export type Method =
  | "GET"
  | "POST"
  | "PUT"
  | "DELETE"
  | "PATCH"
  | "HEAD"
  | "OPTIONS"
  | "TRACE"
  | "CONNECT"
  | "CUSTOM"
  | "get"
  | "post"
  | "put"
  | "delete"
  | "patch"
  | "head"
  | "options"
  | "trace"
  | "connect"
  | "custom";

export interface AxiosRequestConfig {
  url: string;
  method?: Method;
  params?: any;
  data?: any;
  headers?: any;
  timeout?: number;
  withCredentials?: boolean; //携带token
  responseType?: XMLHttpRequestResponseType; //相应类型
}

export interface AxiosResponse<T = any> {
  data: T;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
  request?: any;
}

export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {}

export interface Axios {
  interceptors: {
    request: AxiosInterceptorManager<AxiosRequestConfig>;
    response: AxiosInterceptorManager<AxiosResponse>;
  };
  request<T>(config: AxiosRequestConfig): AxiosPromise<T>;
  get<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  post<T>(
    url: string,
    data?: any,
    config?: AxiosRequestConfig
  ): AxiosPromise<T>;
  put<T>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  delete<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  patch<T>(
    url: string,
    data?: any,
    config?: AxiosRequestConfig
  ): AxiosPromise<T>;
  head<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  options<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  trace<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  connect<T>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
}

export interface AxiosInterceptorManager<T> {
  use(onFulfilled?: ResolveFn<T>, onRejected?: RejectFn<T>): number;
  eject(id: number): void;
}

export interface AxiosInstance extends Axios {
  <T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
}

export interface ResolveFn<T = any> {
  (val: T): T | Promise<T>;
}

export interface RejectFn<T = any> {
  (err: T): any;
}
